import React from "react";
import { Link } from "react-router-dom";
import PageTitle from '../../components/page-title'
import { Button } from 'antd'
import { SnippetsOutlined, DeleteOutlined } from '@ant-design/icons';
import Demo from '../../components/cheackBoxPagination'

class RunHome extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            select: [],
            header: [
                {
                    title: '执行集序号',
                    dataIndex: 'name'
                },
                {
                    title: '执行集描述',
                    dataIndex: 'p1',
                    render: text => <Link >{text}</Link>,
                },
                {
                    title: '详情',
                    dataIndex: 'p2',
                    render: (text,index)=> <Button onClick={()=>{this.myOnclick(index)}} ><Link>{text}</Link></Button>,
                },
            ],
            data: [
                {
                    key: '1',
                    name: '100',
                    p1: '连续交易执行集',
                    p2: '查看'
                },
                {
                    key: '2',
                    name: '99',
                    p1: '集合竞价执行集',
                    p2: '查看'
                },
                {
                    key: '3',
                    name: '98',
                    p1: '白盘执行集',
                    p2: '查看'
                },
                {
                    key: '4',
                    name: '98',
                    p1: '夜盘执行集',
                    p2: '查看'
                },
            ]
        }
    }
    deleteWhat(e) {
        console.log(e)
        this.setState({
            select: e
        })
    }

    delete() {
        //数组合并去重
        let arr1 = this.state.data
        let arr2 = this.state.select
        arr1 = arr1.filter(item => {
            let idList = arr2.map(v => v.key)
            return !idList.includes(item.key)

        })
        this.setState({
            data: arr1
        })
        alert("还有验证和请求没有写,记得记得记得")
    }

    myOnclick(e){
        console.log(e.name)
    }

    render() {
        return (
            <div id="page-wrapper">
                <PageTitle title="用例选取" />

                <Button type="primary" icon={<SnippetsOutlined />}>
                    <Link to='/RunAdd' style={{ color: '#FFFFFF' }}>新建执行集</Link>
                </Button>

                <Button style={{ marginLeft: "10px" }} 
                        type="ghost" danger={true} 
                        onClick={()=>this.delete()}
                        icon={<DeleteOutlined />}>
                    删除
                </Button>

                <Demo columns={this.state.header}
                    dataSource={this.state.data}
                    delete={e => this.deleteWhat(e)}
                />
            </div>
        )
    }
}



export default RunHome